/*
  将下面异步代码使用 Promise 的方法改进
  尽量用看上去像同步代码的方式
  setTimeout(function () {
    var a = 'hello'
    setTimeout(function () {
      var b = 'lagou'
      setTimeout(function () {
        var c = 'I ♥ U'
        console.log(a + b +c)
      }, 10)
    }, 10)
  }, 10)
*/

/* Promise.resolve(a).then(val => 'lagou').then(val => {
  let c = 'I ♥ U'
  console.log(a + val + c);
}) */

//方案1 最简洁，但和settimeout方式比逻辑有点不一样
Promise.resolve("hello").then(a => a + "lagou").then(b => b + "I ♥ U").then(console.log)

//方案2 微任务方式
Promise.all(["hello", 'lagou', 'I ♥ U']).then(res => {
  console.log(res.join(''))
})

//方案3 带异步性质
Promise.all([asyncGetData('hello'),asyncGetData('lagou'),asyncGetData('I ♥ U')]).then(res=>{
  console.log(res.join(''));
})
function asyncGetData(param) {
  return new Promise((resolve,reject) => {
    resolve(param)
  })
}